package com.wzq.design.business.base.user.controller;

import com.wzq.design.base.controller.CommController;
import com.wzq.design.base.dto.QueryByIdRequest;
import com.wzq.design.business.base.user.dto.BaseUserDto;
import com.wzq.design.business.base.user.dto.UserRequest;
import com.wzq.design.business.base.user.service.UserService;
import com.wzq.ssm.parent.base.dto.JsonResult;
import com.wzq.ssm.parent.base.dto.Page;
import com.wzq.design.base.dto.RemoveRequest;
import org.springframework.web.bind.annotation.*;

/**
 * @author wangzhiqiang
 * @since 2023/5/8 15:07
 */
@RestController
@RequestMapping("/base/user")
public class UserController extends CommController {
    private final UserService userService;

    public UserController(UserService userService) {
        this.userService = userService;
    }


    @PostMapping("/list")
    public JsonResult<Page<BaseUserDto>> list(@RequestBody UserRequest userRequest) {
        return JsonResult.success("查询成功", userService.list(userRequest));
    }


    @PostMapping("/delete")
    public JsonResult<?> delete(@RequestBody RemoveRequest request) {
        userService.deleteByIds(request.getIds());
        return JsonResult.success("删除成功");
    }

    @PostMapping("/save")
    public JsonResult<BaseUserDto> save(@RequestBody BaseUserDto request) {
        return JsonResult.success("保存成功", userService.save(request));
    }
    @PostMapping("/resetPassword")
    public JsonResult<?> resetPassword(@RequestBody BaseUserDto request) {
        userService.resetPassword(request);
        return JsonResult.success("保存成功");
    }


    @GetMapping("/findById")
    public JsonResult<BaseUserDto> findById( QueryByIdRequest request) {
        return JsonResult.success("保存成功", userService.findById(request));
    }
}
